package com.v2future.sjt.collegecheckingattendance.leave.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.leave.bean.CourseUnitBean;
import com.v2future.sjt.collegecheckingattendance.leave.bean.OneCourseLeaveBean;
import com.v2future.sjt.collegecheckingattendance.utils.DateUtil;
import com.v2future.sjt.collegecheckingattendance.utils.WidgetUtil;

import java.util.List;

/**
 * 课时假请假记录
 * @author shijianting
 * @time 2016/4/23 9:06
 */
public class CourseLeaveRecordAdapter extends BaseAdapter {

    Context mContext;
    List<OneCourseLeaveBean> dataList;

    public CourseLeaveRecordAdapter(Context mContext, List<OneCourseLeaveBean> dataList) {
        this.mContext = mContext;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        OneCourseLeaveBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_course_leave_record, null);
            holder = new ViewHolder();
            holder.leaveDateTv = (TextView) convertView.findViewById(R.id.tv_leave_date);
            holder.weekdateTv = (TextView) convertView.findViewById(R.id.tv_weekday);
            holder.courseNumberTv = (TextView) convertView.findViewById(R.id.tv_course_number);
            holder.applyDateTv = (TextView) convertView.findViewById(R.id.tv_apply_datetime);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        WidgetUtil.setText(holder.leaveDateTv, bean.getActionStTime());
        WidgetUtil.setText(holder.weekdateTv, DateUtil.getWeekOfDate(bean.getActionStTime()));
        WidgetUtil.setText(holder.courseNumberTv, "第"+bean.getCourseNumber()+"节课");
        WidgetUtil.setText(holder.applyDateTv, bean.getActionTime());
        return convertView;
    }

    public class ViewHolder {
        TextView leaveDateTv;
        TextView weekdateTv;
        TextView courseNumberTv;
        TextView applyDateTv;

    }
}
